#!/usr/bin/env python
# -*- coding:utf-8 -*-
#/home/zc/workspace/tinyfeet/trunk/src/controllers/tfeet/updatetfeet_handler.py
'''
Created on 2012-4-3

@author: zc
'''
from dbhandle.mysqldb import mysqldb 
from datetime import datetime
from config.sqlmap import SQL_ADD_TFEET, SQL_GET_ADD_TFID, SQL_UPDATE_TFEET

dbo = mysqldb()

def newTFeet( arg ):
    """ 新增tfeet方法"""
    cdate = datetime.now().strftime( "%Y%m%d%H%M%S" )
    try:
        tfid = dbo.insert( 'tfeet', seqname = 'tfid', _test = True,
                          uid = str( arg['uid'] ),
                          location = arg['location'],
                          date = str( arg['date'] ),
                          longitude = arg['long'],
                          latigude = arg['lat'],
                          text = arg['text'],
                          pic_normal = arg['pic_normal'],
                          pic_small = arg['pic_small'],
                          pic_original = arg['pic_original'],
                          source = arg['source'],
                          weibo_id = arg['weibo_id'] )
        res = '{"msg":"200","tfid":"%s"}' % str( tfid )
    except:
        tfid = -1
        res = '{"msg":"202", "errmsg":"新增tfeet失败.","tfid":"-1"}'
    return res


def updateTFeet( arg ):
    """ 更新tfeet方法"""
    cdate = datetime.now().strftime( "%Y%m%d%H%M%S" )
    
    sql = SQL_UPDATE_TFEET % \
        ( arg['location'], str( arg['date'] ), arg['long'] , arg['lat'], arg['text'] , arg['pic_normal'] , arg['pic_small'], arg['pic_original'] , arg['tfid'] )
    
    row = dbo.execsql( sql )
    if row == -1:
        res = '{"msg":"202", "errmsg":"更新tfeet失败.","tfid":"%s"}' % str( arg['tfid'] )
    else:
        res = '{"msg":"200","tfid":"%s"}' % str( arg['tfid'] )
    
    return res
